﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace Oops.Xna.Framework.Graphics
{
	/// <summary>
	/// Defines a timed transformation change during the playing of an <see cref="AnimationClip"/>.
	/// </summary>
	public class Keyframe
	{
		private int boneIndex;
		private TimeSpan time;

		/// <summary>
		/// Gets the transform of the <see cref="Keyframe"/>.
		/// </summary>
		public Matrix Transform;

		public Keyframe(int boneIndex, TimeSpan time, Matrix transform)
		{
			this.boneIndex = boneIndex;
			this.time = time;
			this.Transform = transform;
		}

		/// <summary>
		/// Gets the bone index of the <see cref="Keyframe"/>.
		/// </summary>
		public int BoneIndex
		{
			get { return this.boneIndex; }
		}

		/// <summary>
		/// Gets the time of the <see cref="Keyframe"/>.
		/// </summary>
		public TimeSpan Time
		{
			get { return this.time; }
		}

		internal static Keyframe Read(ContentReader input)
		{
			return new Keyframe(
				input.ReadObject<int>(), 
				input.ReadObject<TimeSpan>(), 
				input.ReadObject<Matrix>());
		}
	}

	/// <summary>
	/// Worker for reading a <see cref="Keyframe"/> instance from a binary format.
	/// </summary>
	public class KeyframeReader : ContentTypeReader<Keyframe>
	{
		#region ContentTypeReader<Keyframe> Members

		protected override Keyframe Read(ContentReader input, Keyframe existingInstance)
		{
			return Keyframe.Read(input);
		}

		#endregion
	}
}
